package org.jetnuke.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TextUtilities {
	private TextUtilities() {
	}

	final static Pattern ptAmp;

	final static Pattern ptLess;

	final static Pattern ptGreat;

	static {
		String regexp = "&(?!amp;)";
		ptAmp = Pattern.compile(regexp);
		regexp = "<";
		ptLess = Pattern.compile(regexp);
		regexp = ">";
		ptGreat = Pattern.compile(regexp);
	}

	public static String replaceAmp(String input) {
		Matcher matcher = ptAmp.matcher(input);
		return matcher.replaceAll("&amp;");
	}

	public static String replaceTags(String input) {

		Matcher matcher = ptLess.matcher(input);
		input = matcher.replaceAll("&lt;");
		matcher = ptGreat.matcher(input);
		return matcher.replaceAll("&gt;");
	}
}
